﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Bussiness;
using System.Media;
using WMPLib;
using System.Drawing;

namespace Presentation.MasterPages
{
    public partial class Site : System.Web.UI.MasterPage
    {
   
        string _path;
        bool _esAdmin = false;
        bool _isLogged = false;

        protected override void OnInit(EventArgs e)
        {
            _isLogged = getIsLogged();
            _path = Request.AppRelativeCurrentExecutionFilePath;
            _esAdmin = _path.Contains("Admin") || _path.Contains("admin");

            if (!_isLogged && _esAdmin && !_path.Contains("Login")) Response.Redirect("~/Admin/Login.aspx");
            if (!Page.IsPostBack)
            {
                if (_esAdmin)
                {
                    fillMenuAdmin(_isLogged);
                }
                else
                {
                    fillMenuClient();
                }
                setSelectedMenuTab(_path);
            }

            //if (_esAdmin) MusicPlayerPanel.Visible = false;
        }

        private bool getIsLogged()
        {
            bool result = false;
            try
            {
                result = (bool)Session["isLogged"];
            }
            catch (Exception ex)
            { 
                
            }
            return result;
        }

        private void fillMenuAdmin(bool isLogged)
        {
            menuHeader.Items.Clear();
            foreach (MenuItem i in ControladoraUI.GetMenuAdminItems(isLogged))
            {
                menuHeader.Items.Add(i);
            }
        }

        protected void fillMenuClient()
        {
            menuHeader.Items.Clear();
            foreach (MenuItem i in ControladoraUI.GetMenuClientItems())
            {
                menuHeader.Items.Add(i);
            }
        }

        private void setSelectedMenuTab(string path)
        {
            foreach (MenuItem item in menuHeader.Items)
            {
                item.Selected = item.NavigateUrl.Equals(path, StringComparison.InvariantCultureIgnoreCase);
            }
        }

        //private bool getMusic()
        //{
        //    bool result = true;
        //    try
        //    {
        //        result = (bool)Session["music"];
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //    return result;
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (getMusic())
            //{ musicOn(); }
            //else 
            //{ musicOff(); }
        }

        //protected void hypMusicOn_OnClick(object sender, EventArgs e)
        //{
        //    musicOn();
        //}

        //protected void hypMusicOff_OnClick(object sender, EventArgs e)
        //{
        //    musicOff();
        //}

        //private void musicOff()
        //{
        //    AudioControl.AutoPlay = false;
        //    hypMusicOff.ForeColor = Color.Red;
        //    hypMusicOn.ForeColor = Color.Silver;
        //    hypMusicOff.Enabled = false;
        //    hypMusicOn.Enabled = true;
        //    Session.Add("music", false);
        //}

        //private void musicOn()
        //{
        //    AudioControl.AutoPlay = true;
        //    hypMusicOff.ForeColor = Color.Silver;
        //    hypMusicOn.ForeColor = Color.Red;
        //    hypMusicOn.Enabled = false;
        //    hypMusicOff.Enabled = true;
        //    Session.Add("music", true);
        //}
    }
}